package cn.fl.insroute.service.impl;

import java.util.List;

import cn.fl.insroute.api.IInsRouteModifyApiService;
import cn.fl.insroute.api.IInsRouteQueryApiService;
import cn.fl.insroute.condition.InsRoutePrdInfoQC;
import cn.fl.insroute.voTransform.InsRoutePrdInfoVOTransform;
import com.alibaba.fastjson.JSON;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.fl.insroute.dto.InsRoutePrdInfoDTO;
import cn.fl.insroute.service.IInsRoutePrdInfoService;
import cn.fl.insroute.vo.InsRoutePrdInfoVO;
import cn.fl.framework.base.context.CurrentThreadContext;
import cn.cmm.base.framework.utils.BaseLogUtils;
import cn.cmm.base.framework.utils.CollectionUtils;
import cn.cmm.base.framework.utils.StringUtils;
import cn.cmm.base.framework.utils.BaseLogUtils;
import cmm.mid.core.framework.page.Pager;
import cn.cmm.base.framework.exception.BaseException;

/**
 * @Description: 路由车辆信息 客户端服务层接口实现
 * @Description: 业务层方法名称前缀：新增：add* 删除：remove* 修改：modify* 查询对象：select* get* 批量：batch* 查询集合：search*
 */
@Service
public class InsRoutePrdInfoServiceImpl implements IInsRoutePrdInfoService {

	/**
	 * 日志
	 */
	private static final Logger logger = LoggerFactory.getLogger(IInsRoutePrdInfoService.class);

	/**
	 * TODO 自定义 API 暴露服务
	 */
	//@Autowired
	//private I自定义ApiService 自定义ApiService;

	@Autowired
	private IInsRouteQueryApiService iInsRouteQueryApiService;

	@Autowired
	private IInsRouteModifyApiService iInsRouteModifyApiService;

	@Override
	public InsRoutePrdInfoVO selectById(Long id) throws BaseException{
		if(StringUtils.isEmpty(id)){
			BaseLogUtils.info(logger, "selectById", "主键参数不能为空!", CurrentThreadContext.getCurrentUserName());
			return null;
		}
		InsRoutePrdInfoDTO dto = this.iInsRouteQueryApiService.selectInsRoutePrdInfoDTOById(id);
		return InsRoutePrdInfoVOTransform.toVO(dto);
	}

	@Override
	public Long add(InsRoutePrdInfoVO entity) throws BaseException{
		if(null == entity){
			BaseLogUtils.info(logger, "add", "新增对象不能为空!", CurrentThreadContext.getCurrentUserName());
			return null;
		}
		return this.iInsRouteModifyApiService.addInsRoutePrdInfoDTO(InsRoutePrdInfoVOTransform.toDTO(entity));
	}

	@Override
	public boolean removeById(Long id) throws BaseException{
		if(StringUtils.isEmpty(id)){
			BaseLogUtils.info(logger, "removeById", "删除主键参数不能为空!", CurrentThreadContext.getCurrentUserName());
			return false;
		}
		return this.iInsRouteModifyApiService.removeInsRoutePrdInfoById(id);
	}

	/**
	 * 删除
	 * @param ids
	 * @return
	 */
	public boolean removeByIds(List<Long> ids)throws BaseException{
		if(CollectionUtils.isEmpty(ids)){
			BaseLogUtils.info(logger, "removeByIds", "删除主键参数集合不能为空!", CurrentThreadContext.getCurrentUserName());
			return false;
		};
		return false;
	}

	@Override
	public boolean modify(InsRoutePrdInfoVO entity) throws BaseException{
		if(null == entity){
			BaseLogUtils.info(logger, "modify", "修改对象参数不能为空!", CurrentThreadContext.getCurrentUserName());
			return false;
		}
		return this.iInsRouteModifyApiService.modifyInsRoutePrdInfoDTO(InsRoutePrdInfoVOTransform.toDTO(entity));
	}

	@Override
	public Pager searchListPage(Pager page) throws BaseException{
		if(null == page)page = new Pager();
		//return this.insRoutePrdInfoApiService.searchListPage(page);
		//TODO 业务逻辑
		return null;
	}

	@Override
	public List<InsRoutePrdInfoVO> searchList(InsRoutePrdInfoQC insRoutePrdInfoQC) throws BaseException {
		BaseLogUtils.info(logger,"routeRes","条件查询路由设备信息.请求参数insRoutePrdInfoQC：" + JSON.toJSONString(insRoutePrdInfoQC),CurrentThreadContext.getCurrentUserName());
		List<InsRoutePrdInfoDTO> insRoutePrdInfoDTOS = this.iInsRouteQueryApiService.searchInsRoutePrdInfoDTOList(insRoutePrdInfoQC);
		BaseLogUtils.info(logger,"routeRes","条件查询路由设备信息.返回结果insRoutePrdInfoDTOS：" + JSON.toJSONString(insRoutePrdInfoDTOS),CurrentThreadContext.getCurrentUserName());
		return InsRoutePrdInfoVOTransform.toVOList(insRoutePrdInfoDTOS);
	}
}
